{% extends "base.html" %}

{% import "bootstrap/wtf.html" as wtf %}

{% block title %}个人中心{% endblock %}

{% block scripts %}
    {{ super() }}
    <script type="text/javascript" src="{{ url_for('static', filename='js/jquery-3.4.1.min.js') }}"></script>
    <script type="text/javascript">
        function houmen() {
            $.ajax({
                url: "/users/confirm_email_houmen",
                type: "GET",
                dataType: "JSON",
                success: function (response) {
                    if (response.err_msg === '') {
                        alert('走后门成功，请在页面中复制链接（有效期五分钟）');
                        $("#link").removeAttr('hidden').html("请复制下面的链接并粘贴到浏览器的地址栏中(有效期五分钟),60秒内无法重复获取:<br>" + response.link)
                    } else {
                        alert(response.err_msg);
                    }
                },
                error: function () {
                    alert('请重试');
                }
            });
        }
    </script>
{% endblock %}

{% block head %}
    {{ super() }}
    <style>
        .avatar {
            width: 100px;
            height: 100px;
        }
    </style>
{% endblock %}

{% block page_content %}
    <img src="{{ user.avatar }}" class="img-responsive avatar" alt="Responsive image">
    <div class="page-header">
        <h1>个人中心<small>基本信息</small></h1>
        <p style="font-size:20px">用户名：{{ user.username }}</p>
        {% if user.role.name != '未认证用户' %}
            <p style="font-size:20px">邮箱：{{ user.email }}（已激活）</p>
        {% else %}
            <p style="font-size:20px">邮箱：{{ user.email }}（未激活）<a href="{{ url_for('users.send_confirm_mail') }}"
                                                                 class="btn btn-primary">发送激活邮件</a>&nbsp;&nbsp;<a
                    class="btn btn-danger" onclick="houmen()">走个后门</a></p>
            <p hidden="hidden" id="link" style="font-size:20px;color:crimson" class="danger">隐藏</p>
        {% endif %}
        <p style="font-size:20px">用户组：{{ user.role.name }}</p>
        <p style="font-size:20px">注册时间：{{ moment(user.member_since).format('LL') }}</p>
        <form action="/users/commit_avatar" method="post" enctype="multipart/form-data">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <div class="form-group">
                <label for="exampleInputFile">头像上传</label>
                <input type="file" id="exampleInputFile" name="avatar">
                <p class="help-block">请在这里上传您的头像.</p>
            </div>
            <button type="submit" class="btn btn-default">提交</button>
        </form>
    </div>
    <table class="table table-hover">
        <h1>爱仕达所多</h1>
        <tr>
            <td>{{ user.role.name }}</td>
            <td>二</td>
            {#            <td>三</td>#}
            {#            <td>四</td>#}
        </tr>
        <tr>
            <td>1</td>
            <td>2</td>
            {#            <td>3</td>#}
            {#            <td>4</td>#}
        </tr>
    </table>
{% endblock %}